import 'package:distribution_mall_flutter/pages/home/home_provider.dart';
import 'package:distribution_mall_flutter/pages/home/widgets/tab.dart';
import 'package:distribution_mall_flutter/provider/common/tab.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:skeletonizer/skeletonizer.dart';

GlobalKey _stickAppBarKey = GlobalKey();
const double scrollPx = 154.6;

class ProductAppbar extends ConsumerWidget {
  final TabController homeTabController;
  final double tabHeight = 92.8;
  final double whiteSpaceHeight = 16;

  const ProductAppbar(this.homeTabController, {super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final tabModal = ref.watch(tabProvider);
    var isTab = ref.watch(homeIsTabProvider);
    return SliverAppBar(
        key: _stickAppBarKey,
        expandedHeight: 0,
        floating: true,
        flexibleSpace: Container(
          color: isTab == true
              ? Colors.white
              : const Color(0xFFF5F6F8), // AppBar的颜色
        ),
        pinned: true,
        // 让头部在滚动时保持固定
        backgroundColor: Colors.white,
        elevation: 0,
        leading: null,
        actions: null,
        bottom: PreferredSize(
          preferredSize:
              // Size.fromHeight(82.8 + (activeIndex != 0 ? filterHeihgt : 0)),
              Size.fromHeight(tabHeight + whiteSpaceHeight),
          child: Column(
            children: [
              Skeleton.ignore(
                  child: HomeTab(
                wrapperHeight: 92.8,
                homeTabController: homeTabController,
              )),
              Container(
                  width: double.infinity,
                  height: whiteSpaceHeight,
                  color: Colors.white)
            ],
          ),
        ));
  }
}
